<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Base\OrderChargeLevel;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

/**
 * 充值挡位.
 */
class ChargeLevelController extends Controller
{
    use ModelForm;

    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('game.top_up'));
            $content->description(trans('game.list'));
            $content->body($this->grid());
        });
    }

    protected function grid()
    {
        $grid = Admin::grid(OrderChargeLevel::class, function (Grid $grid) {
            $grid->id('ID');
            $grid->name(trans('game.gear_name'))->editable();
            $grid->price(trans('game.amount'))->editable();
            $grid->created_at(trans('admin.created_at'));
            $grid->updated_at(trans('admin.updated_at'));
            $grid->disableFilter();
            $grid->disableExport();
        });

        return $grid;
    }

    /**
     * [create 添加挡位].
     *
     * @Author   王文凡
     * @DateTime 2018-04-04
     *
     * @version  1.0
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('game.top_up'));
            $content->description(trans('admin.new'));
            $content->body($this->form());
        });
    }

    protected function form()
    {
        return Admin::form(OrderChargeLevel::class, function (Form $form) {
            $form->text('name', trans('game.gear_name'))->rules('required');
            $form->text('price', trans('game.amount'))->rules('required|integer');
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     *
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header(trans('game.top_up'));
            $content->description(trans('admin.edit'));
            $content->body($this->form()->edit($id));
        });
    }
}
